package reflect;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RefiectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Person p1=new Person();
        System.out.println(p1);

        Person p2=new Person("ls",25);
        System.out.println(p2);

        Class cls=Class.forName("reflect.Person");

        //Construtor的每个实例用于表示一个构造器，使用他们相当于调用该构造器实例化对象
        Constructor con= cls.getConstructor(String.class,int.class);
        Object obj= con.newInstance("ww",38);
        System.out.println(obj);
    }
}
